from mcp.server.fastmcp import FastMCP

# 创建MCP服务实例
mcp = FastMCP("Calculator Server")

@mcp.tool()
def add(a: float, b: float) -> str:
    """加法运算：计算两个数的和"""
    return f"{a} + {b} = {a + b}"

@mcp.tool()
def subtract(a: float, b: float) -> str:
    """减法运算：计算两个数的差"""
    return f"{a} - {b} = {a - b}"

@mcp.tool()
def multiply(a: float, b: float) -> str:
    """乘法运算：计算两个数的积"""
    return f"{a} × {b} = {a * b}"

@mcp.tool()
def divide(a: float, b: float) -> str:
    """除法运算：计算两个数的商"""
    if b == 0:
        return "错误：除数不能为零"
    return f"{a} ÷ {b} = {a / b:.4f}"

if __name__ == "__main__":
    mcp.run(transport="stdio")